package br.edu.ufabc.lnc.peanho.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

import br.edu.ufabc.lnc.peanho.util.ImageUtilities;

@SuppressWarnings("serial")
public class Canvas extends JPanel {

	/** Imagem de fundo da tela */
	private final BufferedImage screen;

	public Canvas(BufferedImage background) {
		if (background != null) {
			this.screen = background;
		} else {
			this.screen = ImageUtilities.createCompatibleImage(500, 400,
					Transparency.OPAQUE, Color.WHITE);
		}
		setPreferredSize(new Dimension(background.getWidth(), background.getHeight()));
		requestFocusInWindow();
	}

	@Override
	public void paintComponent(Graphics g) {
		 super.paintComponent(g);
		 Graphics2D g2d = (Graphics2D) g;
		 g2d.drawImage(screen, 0, 0, this);
	}
}
